/* 用户管理 */
import React, { PureComponent } from 'react';
import { Table, Pagination, DatePicker, Input, Form, Cascader, Select, Button, message, Modal, Upload, Col, Row, Switch } from 'antd';
import AddModal from './AddModal'
import EditModal from './EditModal'
import ShowModal from './ShowModal'
import AnalyzeModal from './AnalyzeModal'
import ExportTimeModal from './ExportTimeModal'
import {
  getPerson, disablePerson, deletePerson, uploadPerson, uploadExamTime, getAuthority,
  downloadExcelWrongStudents, coverPeople, deleteBatchPerson, sendWeixinMessage, changeIsQuent, justUpload,
  uploadPersonForbidden, editRemark
} from '@/services/peoples'
import Authorized from '@/components/Authorized/Authorized'
import { baseurl, getHandle } from '@/services/baseurl'
import { history } from 'umi'
import { isAnte, isDevelopment, isZhengda, hasSend, isBinhai, isZhongZheng, isHengTai, learnTime, learnTimeRate, hasCompany, isXinchengJs, isJianan, isKean, isJuan, isCeshi, isXincheng, hasLearnTime,isAqanshun } from '@/utils/utils'
import styles from './index.less'
const { RangePicker } = DatePicker;
const auditText = isZhongZheng() ? '已完成' : '禁用'
import ExportJsonExcel from 'js-export-excel'
import { is } from 'immutable';
function getType(baoming: number, audit_status: number, forbidden: number, expire: number, is_pay: number, ok: number) {
  if (isZhongZheng()) {
    if (ok) return '(已完成用户)'
    if (expire) return '(超期用户)'
    if (baoming) return '(报名用户)'
    if (audit_status > 0) return '(缴费用户)'
  }
  if (is_pay === 1) return '(线上缴费)'
  if (is_pay === 2) return '(导入用户)'
  return ''
}
class Index extends PureComponent<any, any> {
  constructor(props: any) {
    super(props)
    const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
    this.state = {
      isUserManagent: true,//是否是用户列表
      addVisible: false,
      editVisible: false,
      showVisible: false,
      currentRow: {},
      count: null,
      dataSource: [],
      currentPage: 1,
      id_number: '',
      name: '',
      password: '',
      confirmPassword: '',
      type: '',
      phone: '',
      student_type: '',
      sexy: '',
      exam_date: '',
      duty: '',
      integral: '',
      lessons: [],
      subject: '',
      startDate: '',
      endDate: '',
      company: '',
      userinfo,
      searchDuty: userinfo.student_type ? userinfo.student_type.split(',').map(Number) : '',
      searchType: '1',
      searchName: '',
      loading: true,
      fileList: [],
      uploadVisible: false,
      uploadLoading: false,
      typeList: [],
      analyzeVisible: false,
      warnVisible: false,
      warnData: { id_number: [], id_numbers: [] },
      analyzeData: {},
      selectedRows: [],
      selectedRowKeys: [],
      uploadBatchDeleteVisible: false,
      deleteFileList: [],
      showWechatSend: false,
      sendType: 1,
      sendContent: '您好，距离您的考试时间还有5（4 3 2 1）天，请多登录特种设备在线学习平台进行学习练习吧！',
      sendSubjects: '',
      invoice: '',
      invoice_img: [],
      uploadType: 1,
      exportTime: false,
      searchCompany: '',
      idcard: '',
      origin_idcard: '',
      isUserManagement: true,
      sort: 0,
      showRemark: false,
      remark: '',
      startExamDate: '',
      endExamDate: '',
      photo: '', id_card_front: '', id_card_back: '', diploma: '', family_register: '', month: '', year: '',
      classes: '',
      searchClasses: '',
    }
  }
  renderList = (page: any, sort: any) => {
    const { startDate, endDate, searchType, searchName, searchDuty, searchCompany, startExamDate, endExamDate, searchClasses } = this.state;
    const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
    const student_type = searchDuty[searchDuty.length - 1] ? searchDuty[searchDuty.length - 1] === -1 ? searchDuty[0] : searchDuty[searchDuty.length - 1] : ''
    getPerson({
      page, start_date: startDate, end_date: endDate, company: searchCompany, idcard: sort, studenttype: searchDuty[searchDuty.length - 1] === -1 ? '1' : '0',
      type: searchType, name: searchName, role: userinfo.type, student_type, exam_date: startExamDate, exam_dates: endExamDate, classes: searchClasses,
    }).then(res => {
      if (!res) return;
      this.setState({
        dataSource: res.data,
        count: res.count,
        loading: false
      })
    })
  }
  changeTime = (e: any, str: object) => {
    this.setState({
      startDate: str[0],
      endDate: str[1]
    })
  };
  changeSearchExamDate = (e: any, str: object) => {
    this.setState({
      startExamDate: str[0],
      endExamDate: str[1]
    })
  };
  changeSearchDuty = (e: any) => {
    const student_type = JSON.parse(localStorage.getItem('userinfo') || '').student_type;
    if (student_type) {
      const searchDuty = student_type.split(',').map(Number);
      const eStrging = e.join(',')
      if (!e[0] || e.length < searchDuty.length || (e.length === searchDuty.length && eStrging !== student_type)) {
        return this.setState({
          searchDuty
        })
      }
    }
    this.setState({
      searchDuty: e,
    })
  }
  changeValue = (e: any, name: string) => {
    this.setState({
      [name]: e
    })
  }
  changeValueWithTarget = (e: any, name: string) => {
    this.setState({
      [name]: e.target.value
    })
  }
  searchHanle = () => {
    const { sort } = this.state;
    this.setState({
      loading: true,
      currentPage: 1
    }, () => {
      this.renderList(1, sort)
    })
  }
  showAddPerson = () => {
    this.setState({
      addVisible: true
    })
  }
  hideAddPerson = () => {
    this.setState({
      addVisible: false
    })
  }
  showRow = (row: any) => {
    const {
      id_number,
      type,
      student_type,
      sexy,
      duty, name, subject, subjects, phone, integral, exam_date, company, invoice, invoice_img, idcard,
      photo, id_card_front, id_card_back, diploma, family_register, month, year, classes, } = row;
    this.setState({
      currentRow: row,
      id_number,
      type,
      student_type: student_type && student_type.split(',').map(Number),
      sexy: sexy ? sexy + '' : '',
      duty: duty ? duty * 1 : '',
      name,
      company,
      phone: phone,
      lessons: subject ? subject.split(',').map(Number) : [],
      subject: subjects, integral, exam_date: exam_date && exam_date !== '0000-00-00' ? exam_date : '',
      invoice,
      idcard,
      origin_idcard: idcard,
      photo, id_card_front, id_card_back, diploma, family_register, month, year,
      classes,
      invoice_img: [{
        uid: '-1',
        name: invoice_img,
        status: 'done',
        url: baseurl + invoice_img,
        thumbUrl: baseurl + invoice_img,
      }]
    })
  }
  showEditPerson = (row: any) => () => {
    this.setState({
      editVisible: true,
    })
    this.showRow(row)

  }

  hideEditPerson = () => {
    this.setState({
      editVisible: false,
      password: '',
      confirmPassword: ''
    })
  }
  showPerson = (row: any) => () => {
    this.showRow(row)
    this.setState({
      showVisible: true,
    })
  }
  hideShowPerson = () => {
    this.setState({
      showVisible: false
    })
  }
  changePage = (e: any) => {
    const { sort } = this.state;
    this.setState({
      currentPage: e,
      loading: true
    })
    this.renderList(e, sort)
  }
  changeFile = (info: any, name: string) => {
    let fileList = [...info.fileList];
    fileList = fileList.slice(-1);
    fileList = fileList.map(file => {
      if (file.response) {
        file.url = file.response.url;
      }
      return file;
    });
    this.setState({ [name]: fileList });
  };
  componentDidMount() {
    this.renderList('1', 0)
    this.props.renderType()
    getAuthority({ name: '' }).then(res => {
      this.setState({
        typeList: res
      })
    })
  }
  disableSelectedPerson = () => {
    const { selectedRowKeys, currentPage, selectedRows, sort } = this.state;
    const uid = localStorage.getItem('id') || '';
    for (let i = 0; i < selectedRows.length; i++) {
      const item = selectedRows[i];
      if (item.id == uid) return message.error('无法禁用自身账号')
    }
    disablePerson({ id: selectedRowKeys }).then(res => {
      if (res.status === 1) {
        message.success('操作成功')
        this.setState({
          selectedRowKeys: []
        })
        const name = localStorage.getItem('name')
        const operation = name + auditText + '了' + selectedRowKeys.length + '名学员'
        getHandle({ operation })
        this.renderList(currentPage, sort)
      } else {
        message.error('操作失败')
      }
    })
  }
  deleteHandle = () => {
    const { selectedRowKeys, currentPage, sort } = this.state;
    deletePerson({ id: selectedRowKeys }).then(res => {
      if (res.status === 1) {
        message.success('已删除')
        this.renderList(currentPage, sort)
        const name = localStorage.getItem('name')
        const operation = name + '删除了' + selectedRowKeys.length + '名学员'
        getHandle({ operation })
        this.setState({
          selectedRowKeys: []
        })
      } else {
        message.error('删除失败')
      }
    })
  }
  deletePerson = () => {
    const ids = [452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 486, 487]
    const { selectedRows } = this.state;
    const uid = localStorage.getItem('id') || '';
    for (let i = 0; i < selectedRows.length; i++) {
      const item = selectedRows[i];
      if (item.id == uid && item.type !== 2) return message.error('无法删除自身账号')
      // if (window.location.host === 'xuexi.shejiyuan.com') {
      //   for (let j = 0; j < ids.length; j++) {
      //     if (item.id == ids[j]) {
      //       return message.error('存在无法删除的账号')
      //     }
      //   }
      // }
      if (item.num || item.total || item.correct_total || item.done_num
        || item.percentage || item.rights || item.learn_num || item.learn) {
        return Modal.confirm({
          title: '提示',
          content: '包含已培训的学员，是否删除？',
          onOk: () => {
            this.deleteHandle()
          }
        })
      }
    }
    Modal.confirm({
      title: '提示',
      content: '确定删除选中的用户？',
      onOk: () => {
        this.deleteHandle()
      }
    })
  }
  exportExcel = () => {
    const { startDate, endDate, searchType, searchName, searchDuty, selectedRowKeys, searchClasses } = this.state;

    Modal.confirm({
      title: '提示',
      content: '确定导出用户？',
      okText: '确定',
      cancelText: '取消',
      onOk: () => {
        if (isBinhai()) {
          return window.open(`${baseurl}index/index/derive?start_date=${startDate}&end_date=${endDate}&type=${searchType}&duty=&name=${searchName}&is_sw=2&id=${selectedRowKeys.join(',')}`)
        }

        if (location.href.indexOf('tzPeoples') === -1) {//1是特种作业人员 2是特种设备人员
          window.open(`${baseurl}index/index/derive?start_date=${startDate}&end_date=${endDate}&type=${searchType}&duty=&name=${searchName}&is_sw=2&classes=${searchClasses}`)
        } else {
          window.open(`${baseurl}index/index/derive?start_date=${startDate}&end_date=${endDate}&type=${searchType}&duty=&name=${searchName}&is_sw=1&classes=${searchClasses}`)
        }
      }
    })
  }
  showUpload = (uploadType: number) => () => {
    this.setState({
      uploadVisible: true,
      uploadType
    })
  }
  changeFiles = (info: any) => {
    const fileList = info.fileList;
    let file = null;
    if (fileList.length > 1) {
      file = [fileList[fileList.length - 1]];
    } else {
      file = fileList
    }
    this.setState({
      fileList: file
    })
  }
  uploadPerson = () => {
    const { fileList, uploadType, sort } = this.state;
    if (!fileList[0]) {
      return message.error('请上传文件')
    }
    this.setState({
      uploadLoading: true
    })
    if (uploadType === 3) {
      return uploadPersonForbidden({ file: fileList[0].originFileObj }).then(res => {
        const id_number = res.id_number;
        let warnData = { id_number: [], id_numbers: [], id_numberss: [] }
        this.setState({
          uploadVisible: false
        })
        if (res.num > 0) {
          const name = localStorage.getItem('name');
          const operation = name + auditText + '了' + res.num + '名学员'
          getHandle({ operation })
        }
        for (const key in id_number) {
          const item = id_number[key];
          warnData.id_number.push({ id: item.id_number, name: item.name })
        }
        if (warnData.id_number.length > 0) {
          this.setState({
            warnVisible: true,
            uploadLoading: false,
            warnData,
          })
          return
        }
        message.success('上传成功')
        this.renderList(1, sort)
        this.setState({
          uploadVisible: false,
          fileList: [],
          uploadLoading: false
        })
      })
    }
    if (uploadType === 2) {
      return uploadExamTime({ file: fileList[0].originFileObj }).then(res => {
        const id_number = res.id_number;
        let warnData = { id_number: [], id_numbers: [], id_numberss: [] }
        this.setState({
          uploadVisible: false
        })
        if (res.num > 0) {
          const name = localStorage.getItem('name');
          const operation = name + '更新了' + res.num + '名学员时间'
          getHandle({ operation })
        }
        for (const key in id_number) {
          const item = id_number[key];
          warnData.id_number.push({ id: item.id_number, name: item.name })
        }
        if (warnData.id_number.length > 0) {
          this.setState({
            warnVisible: true,
            uploadLoading: false,
            warnData,
          })
          return
        }
        message.success('上传成功')
        this.renderList(1, sort)
        this.setState({
          uploadVisible: false,
          fileList: [],
          uploadLoading: false
        })
      })
    }
    uploadPerson({ file: fileList[0].originFileObj }).then(res => {
      const id_number = res.id_number;
      const id_numbers = res.id_numbers;
      const id_numberss = res.id_numberss;
      const id_numbersss = res.id_numbersss;
      let warnData = { id_number: [], id_numbers: [], id_numberss: [], id_numbersss: [] }
      this.setState({
        uploadVisible: false
      })
      if (res.num > 0) {
        const name = localStorage.getItem('name');
        const operation = name + '批量增加了' + res.num + '名学员'
        getHandle({ operation })
      }
      for (const key in id_number) {
        const item = id_number[key];
        warnData.id_number.push(item)
      }
      for (const k in id_numbers) {
        const item = id_numbers[k];
        if (item.id) {
          warnData.id_numbers.push(item)
        }
      }
      for (const k in id_numberss) {
        const item = id_numberss[k];
        if (item.id) {
          warnData.id_numberss.push(item)
        }
      }
      for (const k in id_numbersss) {
        const item = id_numbersss[k];
        if (item.id) {
          warnData.id_numbersss.push(item)
        }
      }
      if (warnData.id_number.length > 0 || warnData.id_numbers.length > 0 || warnData.id_numberss.length > 0 || warnData.id_numbersss.length > 0) {
        this.setState({
          warnVisible: true,
          uploadLoading: false,
          warnData
        })
        return
      }
      message.success('上传成功')
      this.renderList(1, sort)
      this.setState({
        uploadVisible: false,
        fileList: [],
        uploadLoading: false
      })
    })
  }
  downloadList = () => {
    const { warnData } = this.state;
    let option = {
      fileName: '人员列表', datas: [{
        sheetData: warnData.id_number,// 数据
        sheetName: 'sheet',// 表名
        sheetFilter: ['name', 'id'],// 列过滤
        sheetHeader: ['姓名', '准考证号'],// 第一行标题
        columnWidths: [20, 20]// 列宽 需与列顺序对应
      }]
    };

    const toExcel = new ExportJsonExcel(option); //new
    toExcel.saveExcel(); //保存
  }
  hideUpload = () => {
    this.setState({
      uploadVisible: false
    })
  }
  showUploadBatchDelete = () => {
    this.setState({
      uploadBatchDeleteVisible: true
    })
  }
  changeBatchDeleteFiles = (info: any) => {
    const fileList = info.fileList;
    let file = null;
    if (fileList.length > 1) {
      file = [fileList[fileList.length - 1]];
    } else {
      file = fileList
    }
    this.setState({
      deleteFileList: file
    })
  }
  batchDeletePersonHandle = () => {
    const { deleteFileList, sort } = this.state;
    if (!deleteFileList[0]) {
      return message.error('请上传文件')
    }
    deleteBatchPerson({ doc: deleteFileList[0].originFileObj }).then(res => {
      if (res.static === 1) {
        if (Number(res.count) < 1) {
          return message.warn('模板内没有人员信息')
        }
        message.success('已删除')
        this.renderList(1, sort)
        this.setState({
          uploadBatchDeleteVisible: false
        })
        const name = localStorage.getItem('name')
        const operation = name + '批量删除了' + res.count + '名学员'
        getHandle({ operation })

      } else {
        message.error('删除失败')
      }
    })
  }
  hideUploadBatchDelete = () => {
    this.setState({
      uploadBatchDeleteVisible: false
    })
  }
  showAnalyze = (row: any) => () => {
    this.setState({
      analyzeVisible: true,
      analyzeData: row
    })
  }
  hideAnalyze = () => {
    this.setState({
      analyzeVisible: false
    })
  }
  hideWarn = () => {
    this.setState({
      warnVisible: false
    })
  }
  downloadExcelWrongStudents = () => {
    const uid = localStorage.getItem('id');
    const { warnData } = this.state
    warnData.uid = uid;
    downloadExcelWrongStudents(warnData).then(res => {
      window.open(baseurl + 'index/index/derive_repetition?uid=' + uid)
    })
  }
  goToMember = (row: any) => () => {
    localStorage.setItem('antd-pro-authority', `["${row.type}"]`);
    localStorage.setItem('name', row.name);
    localStorage.setItem('id_number', row.id_number);
    localStorage.setItem('type', row.type);
    localStorage.setItem('subjects', row.subjects);
    localStorage.setItem('id', row.id);
    localStorage.setItem('userinfo', JSON.stringify(row));
    localStorage.setItem('timestamp', row.timestamp);
    history.push('/dashboard')
    location.reload()
  }
  componentWillUnmount = () => {
    this.setState = (state, callback) => {
      return;
    };
  }
  coverOrigin = () => {
    const { id_number, id_numbers, id_numberss, sort,classes } = this.state.warnData;
    let idNumberList: any = [];
    const wrongUsers = [...id_numbers, ...id_numberss];

    if (wrongUsers[0]) {
      id_number.map((item: any) => {
        wrongUsers.map(wrong => {
          if (item.id !== wrong.id) {
            idNumberList.push(item)
          }
        })

      })
    } else {
      id_number.map((item: any) => {
        idNumberList.push(item)
      })
    }
    Modal.confirm({
      title: '提示',
      content: '确定要覆盖原有用户？',
      onOk: () => {
        if (!idNumberList[0]) return message.error('没有可以覆盖的用户')
       
        coverPeople({ id_number: idNumberList,classes:classes }).then(res => {
          if (res.status === 1) {
            message.success('已覆盖')
            this.renderList(1, sort);
          } else {
            message.error('操作失败')
          }
        })
      }
    })
  }
  justUploadHandle = () => {
    const { id_numbersss, sort } = this.state.warnData;
    Modal.confirm({
      title: '提示',
      content: '确定直接导入？',
      onOk: () => {
        justUpload({ id_numbersss }).then(res => {
          if (res.status === 1) {
            message.success('已导入')
            this.renderList(1, sort);
          } else {
            message.error('操作失败')
          }
        })
      }
    })
  }
  wechatSend = () => {
    this.setState({
      showWechatSend: true
    })
  }
  hideWechatSend = () => {
    this.setState({
      showWechatSend: false
    })
  }
  changeSendType = (sendType: number) => () => {
    this.setState({
      sendType,
      sendContent: sendType === 1
        ? '您好，距离您的考试时间还有5（4 3 2 1）天，请多登录特种设备在线学习平台进行学习练习吧！'
        : '您好，距离您的考试时间已经越来越近了，请多登录特种设备在线学习平台进行学习练习吧！'
    })
  }
  changeSendSubjects = (e) => {
    this.setState({
      sendSubjects: e.target.value
    })
  }
  sendWeixinMessage = () => {
    const { selectedRows, sendType, sendContent, sendSubjects } = this.state;
    if (!sendContent) return message.error('请输入推送内容')
    sendWeixinMessage({ member: selectedRows, name: sendType === 1 ? '模拟考试' : '在线学习', subjects: sendSubjects, content: sendContent }).then(() => {
      message.success('已发送');
      this.setState({
        selectedRowKeys: [],
        selectedRows: [],
        showWechatSend: false
      })
    })
  }
  showExportTime = () => {
    this.setState({
      exportTime: true
    })
  }
  hideExportTime = () => {
    this.setState({
      exportTime: false
    })
  }
  changeSearchQuestion = (id, e) => {
    const { currentPage, sort } = this.state;
    this.setState({
      loading: true
    })
    changeIsQuent({ id, is_quent: e ? 1 : 0 }).then(res => {
      if (res.status === 1) {
        this.renderList(currentPage, sort)
        message.success('操作成功')
      } else {
        message.error('操作失败')
      }
    })
  }
  sortList = () => {
    const { currentPage } = this.state;
    this.setState({
      sort: this.state.sort === 1 ? 0 : 1,
    }, () => {
      this.renderList(currentPage, this.state.sort)
    })

  }
  showRemark = (currentRow: any) => () => {
    this.setState({
      showRemark: true,
      currentRow,
      remark: currentRow.remark
    })
  }

  changeReamrk = () => {
    const { currentRow, remark, currentPage, sort } = this.state;
    editRemark({ id: currentRow.id, remark }).then(res => {
      if (res.status === 1) {
        message.success('操作成功')
        this.renderList(currentPage, sort)
        this.setState({
          showRemark: false
        })
      } else {
        message.success('操作失败')
      }
    })
  }
  render() {
    const { options } = this.props;

    const {
      dataSource, count, currentPage, selectedRowKeys, loading, fileList, uploadVisible, uploadLoading,
      analyzeVisible, warnVisible, warnData, analyzeData, searchDuty, userinfo, uploadBatchDeleteVisible, deleteFileList,
      sendType, showWechatSend, sendContent, selectedRows, uploadType, exportTime, sort, showRemark, remark
    } = this.state;
    const columns = [
      {
        title: <div style={{ cursor: 'pointer' }} onClick={this.sortList}>编号（{sort === 1 ? '编号' : '时间'}）</div>,
        dataIndex: 'idcard',
        render: (idcard: any) => {
          return idcard || '-'
        },
        // sorter:(a,b,e)=>this.sortList(e),
        // sortDirections:['descend']
      },
      {
        title: '准考证号',
        dataIndex: 'id_number',
        render: (id_number: string, row: any) => {
          return id_number + getType(row.baoming, row.audit_status, row.forbidden, row.expire, row.is_pay, row.ok)
        }
      },
      {
        title: '姓名',
        dataIndex: 'name',
      },
      // {
      //   title:'单位部门',
      //   dataIndex: 'student_types',
      //   render: (student_types: string) => {
      //     return  student_types
      //   }
      // },
      {
        title: (hasCompany()) ? '公司名称' : '单位部门',
        dataIndex: 'student_types',
        render: (student_types: string, row: any) => {
          return (hasCompany()) ? row.company : student_types
        }
      },
      {
        title: '培训科目',
        dataIndex: 'subjects',
        render: (subjects: any) => {
          return <p style={{ width: 200 }}>{subjects}</p>
        }
      },
      // {
      //   title: '职务',
      //   dataIndex: 'dutys',
      // },
      {

        title: isAnte() ? '备注' : '电话号码',
        dataIndex: 'phone',
        render: (phone: any) => {
          return phone === '0' || !phone ? '' : phone
        }
      },


      {
        title: '级别',
        dataIndex: 'types',
        render: (types: any, row: any) => {
          return row.type === 2 ? '考生' : (types ? types.name : '-')
        }
      },
      {
        title: '考试时间',
        dataIndex: 'exam_date',
        render: (exam_date: string) => {
          return exam_date && exam_date !== '0000-00-00' && exam_date
        }
      },
      {
        title: '添加时间',
        dataIndex: 'created_ats',
        render: (created_ats: any, row: any) => {
          return created_ats || row.created_at
        }
      },

      {
        title: '操作',
        dataIndex: 'id',
        render: (id: any, row: any) => {
          const renderStyle = () => {
            const num = row.num + row.wrong_done_num;
            if (num <= 5) {
              return { marginRight: 10, background: "#ff0000", color: '#fff', borderRadius: '10px', padding: '0 5px', display: 'inline-block' };
            }
            if (num > 5 && num <= 10) {
              return { marginRight: 10, background: "#f99738", color: '#fff', borderRadius: '10px', padding: '0 5px', display: 'inline-block' };
            }
            if (num > 10 && num <= 15) {
              return { marginRight: 10, background: "#d905ff", color: '#fff', borderRadius: '10px', padding: '0 5px', display: 'inline-block' };
            }

            return { marginRight: 10, display: 'inline-block', padding: '0 5px', };
          }
          return <div style={{ width: 115 }}>
            <a style={{ marginRight: 10 }} onClick={this.showPerson(row)}>查看</a>

            <Authorized authority={[103, 903]}>
              <a style={{ marginRight: 10 }} onClick={this.showEditPerson(row)}>修改</a>
            </Authorized>
            <a style={renderStyle()} onClick={this.showAnalyze(row)}>统计</a>
            {
              isZhongZheng() && <Authorized authority={[121, 122, 921, 922]}> <a style={{ marginRight: 10 }} onClick={this.showRemark(row)}>备注</a></Authorized>
            }
            {
              (
                (userinfo.super === 1 && !row.types) || location.host === 'lyxiehui.shejiyuan.com') &&
              <a
                style={{ marginRight: 10 }}
                onClick={this.goToMember(row)}>会员</a>
            }
            {
              (isHengTai() || isZhongZheng()) && <Authorized authority={[118, 918]}><Switch checked={row.is_quent === 1} checkedChildren="搜题启用" unCheckedChildren="搜题关闭" onChange={(e: any) => this.changeSearchQuestion(id, e)} /></Authorized>
            }

          </div>;
        },
      },
    ];
    if (isAnte() || isBinhai() || isJianan() || isKean() || isXinchengJs()) {//如果是安特、滨海的就不要考试时间了
      columns.splice(7, 1)
    }
    if (!isZhongZheng()) {//不是中正就不需要编号了
      columns.splice(0, 1)
    }
    if (isZhongZheng()) {
      columns.splice(7, 1);
      columns.splice(8, 0, {
        title: '备注',
        dataIndex: 'remark',
        render: (remark: string) => {
          return <Input.TextArea readOnly style={{ width: 100 }} value={remark}></Input.TextArea>
        }
      })
    }
    if (isAqanshun()) {
      columns.splice(6, 1);
      columns.splice(6, 0, {
        title: '班级',
        dataIndex: 'classes',
        render: (classes: any) => {
          return classes === '0' || !classes ? '' : classes;
        },
      })
    }


    if (isAnte()) {
      columns.splice(4, 0, {
        title: '公司名称',
        dataIndex: 'company',
      })
    }


    if (isBinhai() || isKean() || isJuan() || isCeshi() || isXinchengJs() || hasLearnTime()) {//滨海和一般工贸加上学时
      let learn_time = learnTime() * learnTimeRate()
      columns.splice(6, 0, {
        title: '培训学时',
        dataIndex: 'sum_time',
        render: (sum_time: any) => {
          const time = Number((sum_time / (1000 * 60 * 60)).toFixed(2)) * learnTimeRate();

          const rate = Number((time * (100 / learn_time)).toFixed(2))
          return <div>
            <p>{time.toFixed(2)}学时</p>
            <div className={styles['progress']}>
              <p className={styles['progress-text']}>{rate <= 100 ? rate : 100}%</p>
              <div className={styles['progress-inner']}>
                <div style={{ width: (rate <= 100 ? rate : 100) + '%' }} className={styles['progress-bg']}></div>
              </div>
            </div>
          </div>
        }
      })
    }
    const rowSelection = {
      selectedRowKeys,
      onChange: (selectedRowKeys: any, selectedRows: any) => {
        this.setState({
          selectedRowKeys,
          selectedRows
        })
      },
    };

    return (
      <div>
        <div style={{ overflow: 'hidden' }}>
          <Form layout="inline" style={{ marginBottom: 20, float: 'right' }}>
            <Form.Item>
              <RangePicker picker="date" onChange={this.changeTime} />
            </Form.Item>
            {
              isZhengda() && <Form.Item>
                <RangePicker picker="date" placeholder={['考试时间', '考试时间']} onChange={this.changeSearchExamDate} />
              </Form.Item>
            }
           { isAqanshun()&&<Form.Item>
              <Input
                onChange={(e: any) => this.changeValueWithTarget(e, 'searchClasses')}
                placeholder="班级"
              />
            </Form.Item>}
            <Form.Item>
              <Select style={{ width: 100 }} placeholder="请选择搜索类别" onChange={(e: any) => this.changeValue(e, 'searchType')} defaultValue="1">
                <Select.Option value="" key="3">全部</Select.Option>
                <Select.Option value="1" key="1">姓名</Select.Option>
                <Select.Option value="2" key="2">准考证号</Select.Option>
              </Select>
              <Input style={{ width: 150 }} placeholder="请输入搜索信息" onChange={(e: any) => this.changeValueWithTarget(e, 'searchName')} />
            </Form.Item>
            {
              isBinhai() || isZhengda() ? <Form.Item>
                <Input placeholder="请输入搜索公司" onChange={(e: any) => this.changeValueWithTarget(e, 'searchCompany')} />
              </Form.Item> : <Form.Item>
                <Cascader placeholder="请选择搜索部门" value={searchDuty} changeOnSelect options={options} onChange={this.changeSearchDuty} />
              </Form.Item>
            }
            <Form.Item>
              <Button type="primary" onClick={this.searchHanle}>查询</Button>
            </Form.Item>
            <Form.Item>
              <Button type="primary" onClick={this.exportExcel}>导出</Button>
            </Form.Item>
            <Authorized authority={[102, 902]}>
              <Form.Item>
                <Button type="primary" style={{ backgroundColor: '#029b0d', borderColor: "#029b0d" }} onClick={this.showAddPerson} >
                  增加
            </Button>
              </Form.Item>
            </Authorized>
            <Authorized authority={[102, 902]}>
              <Form.Item>
                <Button type="primary" style={{ backgroundColor: '#029b0d', borderColor: "#029b0d" }} onClick={this.showUpload(1)}>
                  批量上传
                </Button>
              </Form.Item>
            </Authorized>
            <Authorized authority={[114, 914]}>
              <Form.Item>
                <Button type="primary" style={{ backgroundColor: '#029b0d', borderColor: "#029b0d" }} onClick={this.showUpload(2)}>
                  上传考试时间
                </Button>
              </Form.Item>
            </Authorized>
            {
              isZhongZheng() && <Authorized authority={[104, 904]}>
                <Form.Item>
                  <Button type="primary" style={{ backgroundColor: '#029b0d', borderColor: "#029b0d" }} onClick={this.showUpload(3)}>
                    上传{auditText}列表
              </Button>
                </Form.Item>
              </Authorized>
            }
            {
              isZhengda() && <Form.Item>
                <Button type="primary" style={{ backgroundColor: '#029b0d', borderColor: "#029b0d" }} onClick={this.showExportTime}>
                  导出学习时长
             </Button>
              </Form.Item>
            }
            <Authorized authority={[105, 915]}>
              <Form.Item>
                <Button type="primary" danger onClick={this.showUploadBatchDelete}>
                  批量删除
            </Button>
              </Form.Item>
            </Authorized>
          </Form>
        </div>

        <Table
          columns={columns}
          pagination={false}
          rowSelection={rowSelection}
          dataSource={dataSource}
          rowKey="id"
          loading={loading}
          scroll={{ x: 1400 }}
          footer={() => (
            <React.Fragment>
              <Authorized authority={[104, 904]}>
                <Button style={{ marginRight: 20, marginLeft: 5 }} type="primary" onClick={this.disableSelectedPerson}>{auditText}所选</Button>
              </Authorized>
              <Authorized authority={[105, 905]}>
                <Button type="primary" danger style={{ marginRight: 20 }} onClick={this.deletePerson}>删除所选</Button>
              </Authorized>
              {
                (isDevelopment() || hasSend()) && <Button type="primary" disabled={selectedRows[0] ? false : true} onClick={this.wechatSend}>微信推送</Button>
              }

            </React.Fragment>
          )}
        ></Table>

        <Pagination
          showQuickJumper
          showSizeChanger={false}
          locale="zh-CN"
          total={count}
          current={currentPage}
          onChange={this.changePage}
          style={{ float: 'right', marginTop: 25 }}
          showTotal={(total, range) => `第${range[0]}条-第${range[1]}条，共 ${total} 条`}
        />

        <AddModal
          renderList={this.renderList}
          hideAddPerson={this.hideAddPerson}
          data={{ ...this.state, ...this.props }}
        />
        <EditModal
          data={{ ...this.state, ...this.props }}
          hideEditPerson={this.hideEditPerson}
          changeFile={this.changeFile}
          changeValue={this.changeValue}
          changeValueWithTarget={this.changeValueWithTarget}
          renderList={this.renderList}
        />
        <ShowModal
          data={{ ...this.state, ...this.props }}
          renderList={this.renderList}
          hideShowPerson={this.hideShowPerson}
        />
        <AnalyzeModal visible={analyzeVisible} onHide={this.hideAnalyze} data={analyzeData} />
        <ExportTimeModal visible={exportTime} onHide={this.hideExportTime} />
        <Modal confirmLoading={uploadLoading} title="批量上传" okText="批量上传" visible={uploadVisible} onCancel={this.hideUpload} onOk={this.uploadPerson}>
          <Form>
            <Form.Item label={uploadType === 1 || 3 ? uploadType === 1 ? '上传用户列表' : `上传${auditText}列表` : '上传时间列表'}>
              <Upload accept=".xlsx,.xls" beforeUpload={() => { return false }} onChange={this.changeFiles} fileList={fileList}>
                <Button type="primary">上传EXCEL列表</Button>
              </Upload>
              <div style={{ marginTop: 20 }}>
                {
                  uploadType === 1 || 3 ? uploadType === 1 ? <a href={baseurl + 'Template.xls'}><Button>下载用户模板</Button></a>
                    : <a href={baseurl + 'AuditTemplate.xls'}><Button>下载{auditText}模板</Button></a>
                    : <a href={baseurl + 'TimeTemplate.xls'}><Button>下载时间模板</Button></a>
                }

              </div>
            </Form.Item>
          </Form>
        </Modal>
        <Modal title="上传反馈" visible={warnVisible} onCancel={this.hideWarn} onOk={this.hideWarn}>
          {
            warnData.id_number && warnData.id_number[0] && uploadType === 1 && <b>以下用户准考证号码或班级重复，请审核后导入
              <Button type="primary" onClick={this.coverOrigin} style={{ marginLeft: 10 }}>覆盖原有用户</Button></b>
          }
          {
            warnData.id_number && warnData.id_number[0] && uploadType === 2 && <b>以下用户不在列表里，请核实信息</b>
          }
          {
            warnData.id_number && warnData.id_number.map((item: any) => {
              return <Row key={item.id}>
                <Col span={10}>{item.id}</Col>
                <Col span={5}>{item.name} </Col>
              </Row>
            })
          }
          {
            warnData.id_number && warnData.id_number[0] && uploadType === 2 && <Button type="primary" onClick={this.downloadList}>下载列表</Button>
          }
          {
            warnData.id_number && warnData.id_number[0] && <br />
          }
          {
            warnData.id_numbers && warnData.id_numbers[0] && <b>以下用户所在部门还未设置，请审核后导入</b>
          }
          {
            warnData.id_numbers && warnData.id_numbers.map((item: any) => {
              return <Row key={item.id}>
                <Col span={5}>{item.name} </Col>
                <Col span={10}>{item.id}</Col>
              </Row>
            })
          }
          {
            warnData.id_numbers && warnData.id_numbers[0] && <br />
          }
          {
            warnData.id_numberss && warnData.id_numberss[0] && <b>以下用户培训科目设置错误，请审核后导入</b>
          }
          {
            warnData.id_numberss && warnData.id_numberss.map((item: any) => {
              return <Row key={item.id}>
                <Col span={5}>{item.name} </Col>
                <Col span={10}>{item.id}</Col>
              </Row>
            })
          }
          {
            warnData.id_numberss && warnData.id_numberss[0] && <br />
          }
          {
            warnData.id_numbersss && warnData.id_numbersss[0] && <b>以下用户身份证号错误</b>
          }
          {
            warnData.id_numbersss && warnData.id_numbersss.map((item: any) => {
              return <Row key={item.id}>
                <Col span={5}>{item.name} </Col>
                <Col span={10}>{item.id}</Col>
              </Row>
            })
          }
          {
            warnData.id_numbersss && warnData.id_numbersss[0] && <Button style={{ marginRight: 20 }} type="primary" onClick={this.justUploadHandle}>直接导入</Button>
          }
          {
            uploadType === 1 && <Button type="primary" style={{ backgroundColor: '#fca53e' }} onClick={this.downloadExcelWrongStudents}>导出有误信息用户excel列表</Button>
          }
        </Modal>
        <Modal title="批量删除" okButtonProps={{ type: 'primary', danger: true }} okText="批量删除" visible={uploadBatchDeleteVisible} onCancel={this.hideUploadBatchDelete} onOk={this.batchDeletePersonHandle}>
          <Form>
            <Form.Item label='上传用户列表'>
              <Upload accept=".xlsx,.xls" beforeUpload={() => { return false }} onChange={this.changeBatchDeleteFiles} fileList={deleteFileList}>
                <Button type="primary">上传EXCEL列表</Button>
              </Upload>
              <div style={{ marginTop: 20 }}>
                <a href={baseurl + 'DeleteTemplate.xls'}><Button>下载用户模板</Button></a>
              </div>
            </Form.Item>
          </Form>
        </Modal>
        <Modal title="微信推送" visible={showWechatSend} onCancel={this.hideWechatSend} footer={
          <React.Fragment>
            <div style={{ display: 'flex', justifyContent: 'center' }}>
              <Button onClick={this.changeSendType(1)} style={{ width: 100, marginRight: 20, color: sendType === 1 ? "#FFF" : '', background: sendType === 1 ? "#F60" : '' }}>考试推送</Button>
              <Button onClick={this.changeSendType(2)} style={{ width: 100, color: sendType === 2 ? "#FFF" : '', background: sendType === 2 ? "#F60" : '' }}>学习推送</Button>
            </div>
            <Button type="primary" style={{ margin: '20px auto', width: 100, display: 'block' }} onClick={this.sendWeixinMessage}>发送</Button>
          </React.Fragment>
        }>
          {/* <Input placeholder="请输入科目（非必填）" onChange={this.changeSendSubjects} style={{ marginBottom: 20 }}></Input> */}
          <Input.TextArea value={sendContent} style={{ height: 100 }} onChange={(e: any) => this.setState({ sendContent: e.target.value })}></Input.TextArea>
        </Modal>
        <Modal title="修改备注"
          onCancel={() => { this.setState({ showRemark: false }) }}
          visible={showRemark}

          footer={[<Authorized key="1" authority={[121, 921]}><Button type="primary" onClick={this.changeReamrk}>修改</Button></Authorized>]}>
          <Input.TextArea placeholder="输入备注" value={remark} onChange={(e) => this.changeValueWithTarget(e, 'remark')}></Input.TextArea>
        </Modal>
      </div>
    );
  }
}

export default Index;
